<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <link rel="stylesheet" href="__TEMP__/shop/new/public/css/common.css">
    <link rel="stylesheet" href="__TEMP__/shop/new/public/css/shop.css">
    {if $colorStyle && $colorStyle!='default'}
    <link rel="stylesheet" href="PLATFORM_NEW_CSS/indexDecorate/css/{$colorStyle}.css">
    {/if}
    <script src="__TEMP__/shop/new/public/scripts/lib/require.js" data-main="__TEMP__/shop/new/public/scripts/app/main"></script>
</head>
<body style="background-color: #fff">
    <div class="v-layout-login">
        <div class="v-head-full">
            <div class="v-head w1200 clearfix">
                <div class="logo-left clearfix">
                    <a href="{:__URL('SHOP_MAIN')}" class="fl"><img src="{$pc_info['logo']}"  alt=""></a>
                    <i class="shu fl"></i>
                    <span class="title fl">会员注册</span>
                </div>
                <div class="registered-right fr">已经注册？<a href="{:__URL('SHOP_MAIN/login/index')}">登录></a></div>
            </div>
        </div>

        <div class="v-login-bg" style="background: url('{if $pc_info['pc_register_adv']}{$pc_info['pc_register_adv']}{else}__STATIC__/images/reg.png{/if}') no-repeat center">
            <div class="v-login clearfix w1200">
                <div class="imgHref fl"><a href="{$pc_info['pc_register_jump']}"></a></div>
                <div class="login-box fr">
                    <form action="">
                        <h3 class="title">欢迎来到会员注册</h3>
                        <div class="login-msg" style="display: none">
                            <p class="error hint">账户名错误</p>
                        </div>
                        <dl class="clearfix">
                            <dt class="userName fl"><img src="PLATFORM_STATIC/login_register/L-account.png" alt=""></dt>
                            <dd class="userName-ipt fl"><input type="text" id="mobile" class="inputs" placeholder="请输入您的手机号"></dd>
                        </dl>
                        <!--请输入验证码-->
                        <div class="tip clearfix v-code pr" style="display: none">
                            <input type="text" placeholder="请输入验证码" class="v-code-ipt" id="captcha">
                            <a href="javascript:void(0);" class="vCode-a"><img src="{:__URL('SHOP_MAIN/captcha')}" alt="captcha" onclick="this.src='{:__URL('SHOP_MAIN/captcha?tag=1')}'+'&send='+Math.random()"></a>
                        </div>
                        <dl class="clearfix">
                            <dt class="userName fl"><img src="PLATFORM_STATIC/login_register/code.png" alt=""></dt>
                            <dd class="userName-ipt fl pr">
                                <input type="number" class="inputs" id="mobileregistermodel-sms_captcha" placeholder="请输入验证码">
                                <button type="button" class="obtain-code" id="sendOutCode" >获取验证码</button>
                            </dd>
                        </dl>

                        <dl class="clearfix">
                            <dt class="userName fl"><img src="PLATFORM_STATIC/login_register/L-pwd.png" alt=""></dt>
                            <dd class="userName-ipt fl"><input type="password" id="password" class="inputs" placeholder="请输入长度6-20位密码"></dd>
                        </dl>

                        <dl class="clearfix">
                            <dt class="userName fl"><img src="PLATFORM_STATIC/login_register/确认密码.png" alt=""></dt>
                            <dd class="userName-ipt fl"><input type="password" class="inputs" id="repass" placeholder="请输入确认密码"></dd>
                        </dl>
                        <dl class="clearfix">
                            <dt class="userName fl"><img src="PLATFORM_STATIC/login_register/确认密码.png" alt=""></dt>
                            <dd class="userName-ipt fl"><input type="text" class="inputs" id="extend_code" placeholder="请输入邀请码"></dd>
                        </dl>
                        {if $web_info['reg_rule']==1 && $web_info['reg_id']}
                        <div class="tip clearfix">
                            <div class="fl">
                                <input type="checkbox" id="agree">
                                <span class="tip-agreement">我已阅读并接受<a class="blue" target="_blank" {if $web_info['reg_id']} href="{:__URL('SHOP_MAIN/helpcenter/index','id='.$web_info['reg_id'])}"{/if} >《用户注册协议》</a></span>
                            </div>
                        </div>
                        {/if}
                        <div class="submits">
                            <input type="button" class="submit okSubmit btnregister" value="注册">
                        </div>
                        <input type="hidden" id="num">
                    </form>
                </div>
            </div>
        </div>

    </div>
{$bottom}
</body>
<script>
    require(['dialog'],function(dialog){
        function isIE() {
            if (!!window.ActiveXObject || "ActiveXObject" in window){
                location.href="{:__URL('SHOP_MAIN/login/versionLow')}";
            }
        }
        isIE();

        dialog.footerImg();
        var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        loading();
        function loading(){
            $(".rights").css("display","none");
        }
        $("#mobile").change(function(){
            var mobile = $("#mobile").val();
            if(!myreg.test(mobile)){
                $(".hint").html('请输入正确的手机格式');
                $(".login-msg").css("display", "block");
                $("#mobile").focus();
                return false;
            }
            if(myreg.test(mobile)){
                $.ajax({
                    type: "GET",
                    url: "{:__URL('SHOP_MAIN/login/checkMobile')}",
                    data: {"mobile":$('#mobile').val(), "mall_port":4},
                    success: function(data){
                        if(data){
                            $(".hint").html('该手机号已被注册');
                            $("#mobile").val('');
                            $(".login-msg").css("display", "block");
                            $("#mobile").focus();
                        }else{
                            $(".login-msg").css("display", "none");
                        }
                    }
                });
        }
        });

        $("#password").change(function(){
            var password = $("#password").val();
            if(password == ""){
                $(".hint").html('请输入密码');
                $(".login-msg").css("display", "block");
                $("#password").focus();
                return false;
            }else if(password.length<6){
                $(".hint").html('密码最小长度为6');
                $(".login-msg").css("display", "block");
                $("#password").focus();
                return false;
            }else{
                $(".login-msg").css("display", "none");
            }
        });

        $("#repass").change(function(){
            var repass = $("#repass").val();
            var password = $("#password").val();
            if( !(repass == password)){
                $(".hint").html('两次密码不一致');
                $(".login-msg").css("display", "block");
                $("#repass").focus();
                return false;
            }else{
                $(".login-msg").css("display", "none");
            }
        });
        $("#sendOutCode").click(function () {
            var mobile = $("#mobile").val();

            if(mobile == "" || mobile == undefined || mobile == null){
                $(".hint").html('请输入手机号');
                $(".login-msg").css("display", "block");
                $("#mobile").focus();
                return false;
            }else if(!myreg.test(mobile)){
                $(".hint").html('请输入正确的手机格式');
                $(".login-msg").css("display", "block");
                $("#mobile").focus();
                return false;
            }else{
                $.ajax({
                    type: "GET",
                    url: "{:__URL('SHOP_MAIN/login/checkMobile')}",
                    data: {"mobile":mobile},
                    success: function(data){
                        if(data){
                            $(".hint").html('该手机号已被注册');
                            $(".login-msg").css("display", "block");
                            $("#mobile").focus();
                            return false;
                        }else{
                            if ("{$login_verify_code['pc']}" == 1 && $("#num").val() >= 3) {
                                var vertification = $("#captcha").val();
                            }
                            $.ajax({
                                type: "POST",
                                url: "{:__URL('SHOP_MAIN/login/sendsmsregistercode')}",
                                data: {"mobile": mobile, "vertification": vertification},
                                success: function (data) {
                                    if (data['code'] == 0) {
                                        $(".hint").html('发送成功');
                                        $(".login-msg").css("display", "block");
                                        time();
                                    } else {
                                        $(".hint").html('发送失败');
                                        $(".login-msg").css("display", "block");
                                    }
                                }
                            });
                        }
                    }
                });
            }


            });
        var wait=60;
        function time() {
            if (wait == 0) {
                $("#sendOutCode").removeAttr("disabled");
                $("#sendOutCode").html("获取验证码");
                wait = 60;
                return;
            } else {
                $("#sendOutCode").attr("disabled", 'disabled');
                $("#sendOutCode").html(wait+"s");
                wait--;
            }
            setTimeout(function() {
                    time()
                },
                1000);
        }

        $("#captcha").change(function(){
                if("{$login_verify_code['pc']}" == 1 && $("#num").val()>=3) {
                    var vertification = $.trim($('#captcha').val());
                    if (vertification == undefined || vertification == "") {
                        $(".hint").html('请输入验证码');
                        $(".login-msg").css("display", "block");
                        $("#captcha").focus();
                    } else {
                        $(".login-msg").css("display", "none");
                        $.ajax({
                            type: "post",
                            url: "{:__URL('SHOP_MAIN/login/vertify')}",
                            data: {'vertification': vertification},
                            async: false,
                            dataType: 'json',
                            success: function (data) {
                                if (data['code'] == 1) {
                                    $(".login-msg").css("display", "none");
                                } else {
                                    $(".hint").html('验证码错误');
                                    $(".login-msg").css("display", "block");
                                    $("#captcha").focus();
                                    $("#captcha").val('');
                                    $(".verifyimg").attr("src", "{:__URL('SHOP_MAIN / captcha ? tag = 1')}&send=" + Math.random());
                                }
                            }
                        });
                    }
                }
            })
        $(".btnregister").click(function(){
            var agree=$('#agree').is(':checked')?'1':'0';
            var mobile = $("#mobile").val();
            var extend_code = $("#extend_code").val();
            if(mobile == "" || mobile == undefined || mobile == null){
                $(".hint").html('请输入手机号');
                $(".login-msg").css("display", "block");
                $("#mobile").focus();
                return false;
            }else if(!myreg.test(mobile)){
                $(".hint").html('请输入正确的手机格式');
                $(".login-msg").css("display", "block");
                $("#mobile").focus();
                return false;
            }else{
                $(".login-msg").css("display", "none");
            }
            var code = $("#mobileregistermodel-sms_captcha").val();
            if ("{$notice['noticeMobile']}" == 1){
                //短信开启
                if(code == "" || code == undefined || code == null){
                    $(".hint").html('请输入手机验证码');
                    $(".login-msg").css("display", "block");
                    $("#mobileregistermodel-sms_captcha").focus();
                    return false;
                }else if(code.length != 6){
                    $(".hint").html('请输入正确的手机验证码');
                    $(".login-msg").css("display", "block");
                    $("#mobileregistermodel-sms_captcha").val('');
                    $("#mobileregistermodel-sms_captcha").focus();
                }else{
                    $(".login-msg").css("display", "none");
                }
                $.ajax({
                    type:"post",
                    url:"{:__URL('SHOP_MAIN/login/registerCheckCode')}",
                    data:{'send_param':code},
                    async : false,
                    dataType:'json',
                    success:function(data){
                        if (data['code'] < 0) {
                            $("#num").val(data['num']);
                            if ("{$login_verify_code['pc']}" == 1 && data['num'] >= 3) {
                                $(".v-code").css("display", "block");
                            }
                            $(".hint").html(data["message"]);
                            $(".login-msg").css("display", "block");
                            $(".verifyimg").attr("src","{:__URL('SHOP_MAIN/captcha?tag=1')}&send="+Math.random());
                            $("#mobileregistermodel-sms_captcha").focus();
                            return false;
                        }
                    }
                });
            }
            if("{$login_verify_code['pc']}" == 1 && $("#num").val()>=3) {
                var vertification = $.trim($('#captcha').val());
                if (vertification == undefined || vertification == "") {
                    $(".hint").html('请输入验证码');
                    $(".login-msg").css("display", "block");
                    $("#captcha").focus();
                    return false;
                }
            }
            var password = $("#password").val();
            if(password == ""){
                $(".hint").html('请输入密码');
                $(".login-msg").css("display", "block");
                $("#password").focus();
                return false;
            }else if(password.length<6){
                $(".hint").html('密码最小长度为6');
                $(".login-msg").css("display", "block");
                $("#password").focus();
                return false;
            }else{
                $(".login-msg").css("display", "none");
            }
            var repass = $("#repass").val();
            if( !(repass == password)){
                $(".hint").html('两次密码不一致');
                $(".login-msg").css("display", "block");
                $("#repass").focus();
                return false;
            }else{
                $(".login-msg").css("display", "none");
            }
            {if $web_info['reg_rule']==1 && $web_info['reg_id']}
            if(agree == '0'){
                $(".hint").html('需同意用户注册协议');
                $(".login-msg").css("display", "block");
                return false;
            }
            {/if}
            $.ajax({
                type: "POST",
                url: "{:__URL('SHOP_MAIN/login/register')}",
                data: {
                    "mobile" : mobile,
                    "password" : password,
                    "extend_code" : extend_code,
                    "mobile_code": code
                },
                success: function(data){
                    if (data['code'] > 0) {
                        window.location.href = data['url'];
                    }else{
                        $(".hint").html(data['message']);
                        $(".login-msg").css("display", "block");
                        $(".verifyimg").attr("src","{:__URL('SHOP_MAIN/captcha?tag=1')}&send="+Math.random());
                    }
                }
            });
        });
    });

</script>
</html>